package cn.jcet.mapreduce.sort2;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author 鲜磊
 * @Date 2020/12/11 23:22
 */
public class FlowReduce2 extends Reducer<Text,FlowBean2,Text,FlowBean2> {

    private FlowBean2 v = new FlowBean2();

    @Override
    protected void reduce(Text key, Iterable<FlowBean2> values, Context context) throws IOException, InterruptedException {
        int sum_upFlow = 0;
        int sum_dwownFlow = 0;
        for (FlowBean2 value : values) {
            sum_upFlow += value.getUpFlow();
            sum_dwownFlow += value.getDownFlow();
        }
        v.set(sum_upFlow,sum_dwownFlow);

        context.write(key,v);
    }
}
